const conn = require('../../libs/DB/Conn');
const operationRecord = require("../sys/operationRecordAction");
module.exports = async function (params) {
    let checkUserSql = `SELECT      
                          count(*) AS count
                        FROM
                          domain_file                        
                        WHERE domain_name = ? AND domain_id != ? AND delete_sign = 1;`;
    let queryResult = await conn(checkUserSql, [params.domainName,params.domainId]);
    if (queryResult[0].count > 0) {
        return {success: false, message: '此区域名称已存在'};
    }else {
        let insertObj = {
            domain_name: params.domainName,
            district_id: params.districtId,
            address: params.address,
            manager_name: params.managerName,
            manager_mobile: params.managerMobile
        };
        let insertSql = `UPDATE domain_file SET ? WHERE domain_id = ?`;
        await conn(insertSql, [insertObj,params.domainId]);
        await operationRecord(params);
        return {success: true}
    }
};